package scaladuct;

import util.GenericAnalysisUtils;

import java.lang.reflect.Type;

/**
 * Created by IntelliJ IDEA.
 * User: zslajchrt
 * Date: 31.3.11
 * Time: 17:47
 * To change this template use File | Settings | File Templates.
 */
public class BeanInfoRefInfo implements RefInfo {
    private static final long serialVersionUID = 5409742065864507336L;

    private final BeanInfo beanInfo;
    private final String propertyName;

    public BeanInfoRefInfo(BeanInfo beanInfo, String propertyName) {
        this.beanInfo = beanInfo;
        this.propertyName = propertyName;
    }

    @Override
    public Type getType() {
        return beanInfo.propertyGenericType(this.propertyName);
    }

    @Override
    public Class<?> getRawClass() {
        return GenericAnalysisUtils.getRawClassFromType(getType());
    }

    @Override
    public boolean collection() {
        return false;
    }

    @Override
    public String name() {
        Ref ref = beanInfo.propertyAnnotation(this.propertyName, Ref.class);
        return ref == null ? null : ref.name();
    }
}
